import { createRouter, createWebHistory } from 'vue-router'
import { routes } from './routes'

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 全局前置守卫 - 设置页面标题
router.beforeEach((to, from, next) => {
  // 如果路由元信息中定义了标题，则设置文档标题
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

export default router